/*
*TABLE 3
Moderation of Association between Firm-Level Exposure to PSL Mandates and Work- ers' reports of Access to PSL in States and Counties without PSL mandates by Firm Franchising
*/

use "$data_path/main_analysis_file.dta", clear

cd "$exhibits_path"

* defining controls
	global demog i.gender i.race2_harm c.age_text_clean i.kids i.eslhome i.enrolled i.cohabstatus
	global work i.manager i.longwork_yrs i.union c.hourwage_clean c.usualhours_clean 
	global statechars c.unionmem_pc c.unemp_rate  c.minwage_state  	c.race_black c.race_amind c.race_asian c.race_pacisl c.race_multi c.race_other c.hispan c.age_u5 c.age_5to9 c.age_10to14 c.age_75to84 c.age_85plus c.female_pc c.educ_pc_hsgrad c.educ_pc_somecoll c.educ_pc_assoc c.educ_pc_bach c.educ_pc_grad
	global empchars i.shift_ind c.total_emps c.total_ests



*Share in a PSL Covered State or County - Percent of workers covered by PSL * Franchisor Firm
eststo col1row1_3: mi est, post: reg benefits_paidsick c.pct_emps_psl_place##i.franchise_company $demog $work $statechars $empchars i.statelist i.year##i.month if  psl_law_places_hybd == 0, vce(cluster statelist)

*Share in a PSL Covered State or County - Percent of workers covered by PSL * Franchisor Firm (Only Food Ind)
eststo col2row1_3: mi est, post: reg benefits_paidsick c.pct_emps_psl_place##i.franchise_company $demog $work $statechars $empchars i.statelist i.year##i.month if  psl_law_places_hybd == 0 & shift_ind == 8, vce(cluster statelist)

*Share in a PSL Covered State or County - Percent of establishments covered by PSL * Franchisor Firm
eststo col1row4_6: mi est, post: reg benefits_paidsick c.pct_ests_psl_place##i.franchise_company $demog $work $statechars $empchars i.statelist i.year##i.month if  psl_law_places_hybd == 0, vce(cluster statelist)

*Share in a PSL Covered State or County - Percent of establishments covered by PSL * Franchisor Firm (Only Food Ind)
eststo col2row4_6: mi est, post: reg benefits_paidsick c.pct_ests_psl_place##i.franchise_company $demog $work $statechars $empchars i.statelist i.year##i.month if  psl_law_places_hybd == 0 & shift_ind == 8, vce(cluster statelist)

*Share in a PSL Covered State or County - Percent of a firm's workers that are in PSL covered counties
eststo col1row7_9: mi est, post: reg benefits_paidsick c.pct_emps_psl_place##c.percent_franchise $demog $work $statechars $empchars i.statelist i.year##i.month if  psl_law_places_hybd == 0, vce(cluster statelist)

*Share in a PSL Covered State or County - Percent of a firm's workers that are in PSL covered counties (Only Food Ind)
eststo col2row7_9: mi est, post: reg benefits_paidsick c.pct_emps_psl_place##c.percent_franchise $demog $work $statechars $empchars i.statelist i.year##i.month if  psl_law_places_hybd == 0 & shift_ind == 8, vce(cluster statelist)

*Share in a PSL Covered State or County - Percent of a firm's establishments that are in PSL covered counties
eststo col1row10_12: mi est, post: reg benefits_paidsick c.pct_ests_psl_place##c.percent_franchise $demog $work $statechars $empchars i.statelist i.year##i.month if  psl_law_places_hybd == 0, vce(cluster statelist)

*Share in a PSL Covered State or County - Percent of a firm's establishments that are in PSL covered counties (Only Food Ind)
eststo col2row10_12: mi est, post: reg benefits_paidsick c.pct_ests_psl_place##c.percent_franchise $demog $work $statechars $empchars i.statelist i.year##i.month if  psl_law_places_hybd == 0 & shift_ind == 8, vce(cluster statelist)

*Macros to make control labels
estadd local AllInd "\checkmark": col1row10_12
estadd local FoodInd "\checkmark": col2row10_12

*Code to make latex tables
esttab col1row1_3 col2row1_3 using "$exhibits_path/Table 3.tex", ///
	prehead("{\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi} \begin{tabular}{l*{2}{c}} \hline\hline") ///
	fragment keep(pct_emps_psl_place 1.franchise_company 1.franchise_company#c.pct_emps_psl_place) ///
	coeflabel(pct_emps_psl_place "\hspace{0.5cm} Percent of Workers Covered by PSL" 1.franchise_company "\hspace{0.5cm} Franchisor Firm" 1.franchise_company#c.pct_emps_psl_place "\hspace{0.5cm} Percent of Workers Covered by PSL $\times$ Franchisor Firm") ///
	 eqlabels(none) noomitted noconstant nonumbers nonote noobs not nodepvars  label b(%9.3f) ///
	 refcat(pct_emps_psl_place "\vspace{0.1em} \\ \emph{\shortstack[l]{Share in a PSL Covered State or County}}" , nolabel) ///
	 star(+ 0.10 * 0.05 ** 0.01 *** 0.001) ///
	 	 mgroups("\shortstack{PSL Access in Non-Mandate Places}", pattern(1 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) ///
		 mtitles("All Industries" "Food Industry") ///
	replace 

esttab col1row4_6 col2row4_6 using "$exhibits_path/Table 3.tex", ///
	fragment keep(pct_ests_psl_place 1.franchise_company 1.franchise_company#c.pct_ests_psl_place) b(%9.3f) ///
		coeflabel(pct_ests_psl_place "\hspace{0.5cm} Percent of Establishments Covered by PSL" 1.franchise_company "\hspace{0.5cm} Franchisor Firm" 1.franchise_company#c.pct_ests_psl_place "\hspace{0.5cm} Percent of Establishments Covered by PSL $\times$ Franchisor Firm") ///
		refcat(pct_ests_psl_place "\vspace{0.1em} \\ \emph{\shortstack[l]{Share in a PSL Covered State or County}}" , nolabel) ///
	nomtitles eqlabels(none) noomitted noconstant not nonote noobs  nodepvars nonumbers nolines label /// 
	 star(+ 0.10 * 0.05 ** 0.01 *** 0.001) ///
	append	
	
esttab col1row7_9 col2row7_9 using "$exhibits_path/Table 3.tex", ///
	fragment keep(pct_emps_psl_place percent_franchise c.pct_emps_psl_place#c.percent_franchise) b(%9.3f) ///
		coeflabel(pct_emps_psl_place "\hspace{0.5cm} Percent of Workers Covered by PSL" percent_franchise "\hspace{0.5cm} Percent Franchised" c.pct_emps_psl_place#c.percent_franchise "\hspace{0.5cm} Percent of Firm's Workers Covered by PSL $\times$ Percent Franchised") ///
	nomtitles eqlabels(none) noomitted noconstant not nonote noobs  nodepvars nonumbers nolines label /// 
	 refcat(pct_emps_psl_place "\vspace{0.1em} \\ \emph{\shortstack[l]{Share in a PSL Covered State or County}}" , nolabel) ///
	 star(+ 0.10 * 0.05 ** 0.01 *** 0.001) ///
	append	
	
	
esttab col1row10_12 col2row10_12 using "$exhibits_path/Table 3.tex", ///
	fragment keep(pct_ests_psl_place percent_franchise c.pct_ests_psl_place#c.percent_franchise) b(%9.3f) ///
			coeflabel(pct_ests_psl_place "\hspace{0.5cm} Percent of Establishments Covered by PSL" percent_franchise "\hspace{0.5cm} Percent Franchised" c.pct_ests_psl_place#c.percent_franchise "\hspace{0.5cm} Percent of Firm's Establishments Covered by PSL $\times$ Percent Franchised") ///
	nomtitles eqlabels(none) noomitted noconstant not nonote noobs  nodepvars nonumbers nolines label /// 
		postfoot("\hline\hline \multicolumn{3}{l}{\footnotesize \sym{+} \(p<0.10\), \sym{*} \(p<0.05\), \sym{**} \(p<0.01\), \sym{***} \(p<0.001\)}\\ \end{tabular} } ") ///
	 refcat(pct_ests_psl_place "\vspace{0.1em} \\ \emph{\shortstack[l]{Share in a PSL Covered State or County}}" , nolabel) ///
	 prefoot("\vspace{0.1em} \\") ///
	 	scalars("line \hline \vspace{-.5em}" "N N") sfmt(%9.0f) ///
	 star(+ 0.10 * 0.05 ** 0.01 *** 0.001) ///
	append	
